[Minor] Reuse indices buffer in RepartitionExec#19775
Merged
Dandandan merged 4 commits intoapache:mainfrom Jan 16, 2026
Merged
Conversation
This commit optimizes the `RepartitionExec` operator by reusing the `Vec` allocations for indices in the `BatchPartitioner`. Instead of reallocating the `indices` vector for every `RecordBatch` it processes in hash partitioning mode, this change modifies the `BatchPartitioner` to reuse these allocations across batches. This is achieved by: - Storing the `indices` vectors in the `BatchPartitionerState`. - Clearing the vectors for each new batch. - Using `std::mem::take` to move the data out for processing. - Reclaiming the underlying `Vec` from the Arrow array using `into_parts` after processing, clearing it, and placing it back into the state for the next iteration. This avoids repeated allocations and improves performance, especially when dealing with many small batches.
Contributor
Author
|
Run benchmarks |
|
🤖 |
|
🤖: Benchmark completed Details
|
Contributor
Author
|
Run benchmarks |
Contributor
Author
|
run benchmark tpch tpcds |
1 similar comment
Contributor
Author
|
run benchmark tpch tpcds |
Contributor
Author
|
run benchmark tpch tpcds |
comphead
reviewed
Jan 14, 2026
comphead
reviewed
Jan 14, 2026
| let mut partitioned_batches = vec![]; | ||
| for (partition, p_indices) in indices.iter_mut().enumerate() { | ||
| if !p_indices.is_empty() { | ||
| let taken_indices = std::mem::take(p_indices); |
Contributor
There was a problem hiding this comment.
just wondering if we can use drain https://doc.rust-lang.org/std/vec/struct.Vec.html#method.drain so you can get rid of clearing them?
comphead
approved these changes
Jan 14, 2026
Contributor
comphead
left a comment
There was a problem hiding this comment.
Thanks @Dandandan it looks good to me, left some notes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit optimizes the
RepartitionExecoperator by reusing theVecallocations for indices in theBatchPartitioner. Instead of reallocating theindicesvector for everyRecordBatchit processes in hash partitioning mode, this change modifies theBatchPartitionerto reuse these allocations across batches.This is achieved by:
indicesvectors in theBatchPartitionerState.std::mem::taketo move the data out for processing.Vecfrom the Arrow array usinginto_partsafter processing, clearing it, and placing it back into the state for the next iteration.This avoids repeated allocations and improves performance, especially when dealing with many small batches.
Which issue does this PR close?
Rationale for this change
What changes are included in this PR?
Are these changes tested?
Are there any user-facing changes?